package logic

import (
	"context"
	"user-management/usersrpc/models/mysql"

	"user-management/usersrpc/internal/svc"
	"user-management/usersrpc/usersrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddLogic {
	return &UserAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserAddLogic) UserAdd(in *usersrpc.UserAddRequest) (*usersrpc.UserAddResponse, error) {
	// todo: add your logic here and delete this line
	user := mysql.User{

		Account:  in.Account,
		Password: in.Password,
	}
	mysql.DB.Debug().Create(&user)
	return &usersrpc.UserAddResponse{
		Id: int64(user.ID),
	}, nil
}
